//
//  IntroViewController.m
//  A_program
//
//  Created by 杨利佳 on 15/5/23.
//  Copyright (c) 2015年 BayMax. All rights reserved.
//

#import "IntroViewController.h"
#import "MusicIntro.h"
#import "MusicThiModel.h"

@interface IntroViewController ()

@end

@implementation IntroViewController

- (void)dealloc
{
    [_model release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.9];
       [self createView];
}


- (void)createView
{
    MusicIntro *introView = [[MusicIntro alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:introView];
    [introView release];
        
    // 返回按钮
    UIButton *top = [[UIButton alloc] initWithFrame:CGRectMake(20, 30, 30, 30)];
    UIImage *aImage = [UIImage imageNamed:@"back.png"];
    UIImage *bImage = [aImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [top setImage:bImage forState:UIControlStateNormal];
    [top addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [introView addSubview:top];
    [top release];
    
    // 赋值
    introView.title.text = self.model.title;
    introView.name.text = self.model.title;
    introView.creater.text = self.model.nickname;
    introView.intro.text = self.model.introRich;
    
    // 设置介绍Label的自适应高度
    NSString *str = self.model.introRich;
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGRect rect = [str boundingRectWithSize:CGSizeMake(200, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    if (rect.size.height < 400) {
        introView.view.frame = CGRectMake(30, 100, self.view.frame.size.width - 60, rect.size.height + 150);
        introView.scroll.frame = CGRectMake(70, 130, introView.view.frame.size.width - 70, rect.size.height) ;
    }
    
    introView.intro.frame = CGRectMake(0, 0, introView.scroll.frame.size.width, rect.size.height);
    introView.scroll.contentSize = CGSizeMake(0, rect.size.height + 10);

}

// 返回上一个界面
- (void)backAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
